package com.test.ssm.service.impl;

import com.test.ssm.dao.StudentDAO;
import com.test.ssm.dao.TeacherDAO;
import com.test.ssm.pojo.User;
import com.test.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @author 徒有琴
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private StudentDAO studentDAO;

    @Autowired
    private TeacherDAO teacherDAO;


    @Override
    public User doLogin(String email, String password, int type) throws Exception {
        //type 1是学生，2是老师
        User user = null;
        if (type == 1) {
            user = studentDAO.getStudentByEmail(email);
        } else if (type == 2) {
            user = teacherDAO.getTeacherByEmail(email);
        } else {
            throw new Exception("用户类型错误");
        }
        //用户名或密码错误
        if (user == null || !password.equals(user.getPassword())) {
            throw new Exception("用户名或密码错误");
        }
        return user;
    }
}
